extends ../layout

block meta
    link(rel="stylesheet", href="#{options.cdn_path}/js/dataTable/css/jquery.dataTables.css?v=#{options.site_version}")
    link(rel="stylesheet", href="#{options.cdn_path}/js/dataTable/css/jquery.dataTables_themeroller.css?v=#{options.site_version}")
    link(rel="stylesheet", href="#{options.cdn_path}/js/jqueryUi/css/jquery-ui.min.css?v=#{options.site_version}")
    link(rel="stylesheet", href="#{options.cdn_path}/js/artDialog/skins/default.css?v=#{options.site_version}")
    style
        .dataTables_length select { width: 80px;}
        .fg-toolbar { height: 30px;}
        //tbody td{height: 46px;line-height: 46px !important;}

block content
    // 传递参数
    accountsClass = true
    include ../common/_admin_navbar
    .content
        .header
            h1.page-title 用户管理
        ul.breadcrumb
            li
                a(href="/admin") 首页
                span.divider /
            li.active 用户中心
        .container-fluid
            .row-fluid
                .well
                    table#otable.table.table-striped.table-bordered(cellpadding="0", cellspacing="0", border="0", width="100%")
                        thead
                            tr
                                th(width="10%") id
                                th(width="10%") 昵称
                                th(width="10%") 性别
                                th(width="20%") 博文数
                                th(width="10%") 状态
                                th(width="20%") 状态管理
                                th(width="20%") 权限管理
                        tbody
                include ../common/_admin_footer

block script
    script(src="#{options.cdn_path}/js/dataTable/js/jquery.dataTables.min.js?v=#{options.site_version}")
    script(src="#{options.cdn_path}/js/artTemplate/js/template.min.js?v=#{options.site_version}")
    script(src="#{options.cdn_path}/js/artDialog/jquery.artDialog.min.js?v=#{options.site_version}")
    script#statusTemp(type="text/html")
        |<% if (status == '0') { %>
        |<span class="badge badge-success">正常</span>
        |<% } else if ( status == '1' ) { %>
        |<span class="badge badge-warning">已删</span>
        |<% } %>
    script#manageTemp(type="text/html")
        |<a href="/admin/user/update_status/<%=id%>" class="update_status">
        |<% if (status == '0') { %>
        |<i class="icon-remove"></i>删除
        |<% } else if ( status == '1' ) { %>
        |<i class="icon-ok"></i>显示
        |<% } %>
        |</a>
    script#roleTemp(type="text/html")
        |<select class="update_role span6" data-url="/admin/user/update_role/<%=id%>">
        |<option value="0" <% if (role == '0') { %>selected<% } %> >普通</option>
        |<option value="1" <% if (role == '1') { %>selected<% } %> >VIP</option>
        |<option value="2" <% if (role == '2') { %>selected<% } %> >管理员</option>
        |<select>
    script
        $(function(){
            $('#otable').dataTable({
                "bLengthChange": true,
                "bFilter": true, //搜索栏
                "bSort": false, //是否支持排序功能
                "bInfo": true, //显示表格信息
                "bStateSave": false, 
                "sPaginationType": "full_numbers", //分页，一共两种样式，full_numbers和two_button(默认)
                "bProcessing": true,
                "bServerSide": true,
                "iDisplayLength": 10,
                "oLanguage": {
                    "sLengthMenu": "每页显示 _MENU_ 记录",
                    "sZeroRecords": "对不起，查询不到任何相关数据",
                    "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
                    "sInfoEmtpy": "找不到相关数据",
                    "sInfoFiltered": "(数据表中共为 _MAX_ 条记录)",
                    "sProcessing": "正在加载中...",
                    "sSearch": "搜索：",
                    "aaSorting": [[1, "desc"]],  //第一个参数表示表示Browser列。第二个参数为 desc或是asc
                    "oPaginate": {
                        "sFirst":    "首页",
                        "sPrevious": "上一页 ",
                        "sNext":     "下一页 ",
                        "sLast":     "尾页 "
                    }
                }, //多语言配置
                "sAjaxSource": "/admin/user/list_json",
                "bJQueryUI": true,
                "aoColumnDefs": [
                    {
                        "aTargets": [2],
                        "mData": null,
                        "mRender": function (data, type, full) {
                            var sexs = ['女', '男'];
                            return sexs[full[2]];
                        }
                    },{
                        "aTargets": [4],
                        "mData": null,
                        "mRender": function (data, type, full) {
                            return template.render('statusTemp', {status: full[4]});
                        }
                    },{
                        "aTargets": [5],
                        "mData": null,
                        "mRender": function (data, type, full) {
                            return template.render('manageTemp', {id: full[0], status: full[4]});
                        }
                    },{
                        "aTargets": [6],
                        "mData": null,
                        "mRender": function (data, type, full) {
                            return template.render('roleTemp', {id: full[0], role: full[5]});
                        }
                    }
                ],
                "aLengthMenu": [[10, 25, 50], ["10条", "25条", "50条"]]  //设置每页显示记录的下拉菜单
            });
            // update 状态
            $('tbody').on('click', '.update_status', function(){
                var dialog = $.dialog();
                $.post( $(this).attr('href'), function(data) {
                    if(data.status === 2){
                        dialog.content('你没有权限，请联系管理员！').lock().time(2000);
                    } else if(data.status === 3){
                        dialog.content('请不要修改管理员的状态！').lock().time(2000);
                    } else if( data.status ) {
                        dialog.content('状态更新成功！').lock().time(1000);
                        setTimeout(function(){
                            location.reload();
                        }, 1000);
                    } else {
                        dialog.content('操作失败，请稍后再试！').lock().time(2000);
                    }
                });
                return false;
            });
            // update 权限
            $('tbody').on('change', '.update_role', function(){
                var dialog = $.dialog();
                $.post( $(this).data('url'), {role: $(this).find(':selected').val()}, function(data) {
                    if(data.status === 2){
                        dialog.content('你没有权限，请联系管理员！').lock().time(2000);
                    } else if(data.status === 3){
                        dialog.content('请不要修改管理员的权限！').lock().time(2000);
                    }else if( data.status ) {
                        dialog.content('状态更新成功！').lock().time(1000);
                        setTimeout(function(){
                            location.reload();
                        }, 1000);
                    } else {
                        dialog.content('操作失败，请稍后再试！').lock().time(2000);
                    }
                });
                return false;
            });
        });